#ifndef CAMERA_TOPIC_H_
#define CAMERA_TOPIC_H_

#include <iostream>
#include <mutex>
#include <thread>
#include <time.h>
#include <ros/ros.h>
#include <std_msgs/Bool.h>
#include <std_msgs/UInt32.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <opencv2/opencv.hpp>
#include "common_dispatcher_enum.h"

#define IMAGE_SAVE_STAT 0

namespace cameras
{

class CameraTopic
{
private:
    ros::NodeHandle nh_private_;
    ros::Subscriber sub_private_;
    std::mutex camera_mutex_;

    void get_param();
    void camera_state_sub(const std_msgs::UInt32 msg);
    void upper_lower_camera();
    void one_camera();
    void save_img(cv::Mat& image, std::string& dir_path);
    void init_calibration_para();

	bool camera_state_ = false;
	int camera_id_ = 0;
	int camera_rate_ = 30;
	int camera_width_ = 1280;
	int camera_height_ = 720;
	std::string camera_topic_ = "/cameras/front_upper_camera";
	std::string camera_calibration_file_ = "/home/saite/workspace/camera_calibration.yaml";
	std::string cameras_control_topic_ = "/cameras_algorithms_dispatcher/cameras_control";

	int front_lower_camera_id_ = 1;
	std::string front_lower_camera_topic_ = "/cameras/front_lower_camera";
	std::string front_lower_camera_calibration_file_ = "/home/saite/workspace/camera_calibration.yaml";

    cv::Scalar image_sum_;
    bool state_update_ = false;
    int save_count_ = 0;

    int img_sum_count_ = 10;
    int sleep_time_ = 30*1000;
    std::string dir_path = "/home/saite";

	cv::Mat camera_map_pre_;
	cv::Mat camera_map_post_;
	cv::Mat front_lower_camera_map_pre_;
	cv::Mat front_lower_camera_map_post_;
    
public:
    void run();
    CameraTopic(ros::NodeHandle& private_node);
    //CameraTopic();
    ~CameraTopic();
};

}

#endif
